#
# This script creates a database(rarc) that will be used by rarc system.
#

#!/bin/sh

# NOTE! SET THESE VARIABLES
DATABASE_NAME=""
RARC_TABLES_FILE=""
RARC_FUNCTIONS_FILE=""

if [ $# -ne 2 ]
then
 echo "usage: ./setup_rarc_database <username database> <password database>"
 exit 1
fi

USER=$1
PASS=$2

echo "Create database"
mysql -u$USER -p$PASS -e "CREATE DATABASE IF NOT EXISTS $DATABASE_NAME;"

RESULT=`echo $?`
if [ $RESULT = "1" ]
then
 exit 1
fi

echo "Create rarc tables"
mysql -u$USER -p$PASS -D $DATABASE_NAME -e "source $RARC_TABLES_FILE;"

RESULT=`echo $?`
if [ $RESULT = "1" ]
then
 exit 1
fi

echo "Create rarc functions"
mysql -u$USER -p$PASS -D $DATABASE_NAME -e "source $RARC_FUNCTIONS_FILE;"

RESULT=`echo $?`
if [ $RESULT = "1" ]
then
 exit 1
fi

